package com.example.lin.track;

import com.example.lin.util.ExportUtil;
import com.example.lin.util.ImportUtil;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
 * @author GuLin
 * @create 2025-07-05 1:46
 */
public class Leg3Track {

//    public static List<String> listCheck = new ArrayList<>();
//    static {
//        listCheck.add("1047475537213132800");
//        listCheck.add("1047464317366042624");
//    }

    @Test
    public void generateSQLOutText() {
        String filePath = "C:\\Users\\ASUS\\Desktop\\轨迹信息处理\\0704.xlsx";
        String fileName = filePath.substring(filePath.lastIndexOf("\\") + 1, filePath.lastIndexOf("."));
        int sheet = 0;
        String template = "INSERT INTO `t_mq_send_fail` (`id`, `message_type`, `message`, `error_reason`, `retry_status`, `retry_times`, `max_retry_times`, `retry_time`, `is_active`, `create_time`, `create_user_code`, `modify_time`, `modify_user_code`) " +
                "VALUES ('%s', '1', '%s', '%s', '0', NULL, '5', NOW(), '1', NOW(), '181596', NOW(), '181596');";
        List<List<Object>> list = ImportUtil.readExcelToList(filePath, sheet);
        List<Object> sqlList = new LinkedList<>();
        list.forEach(e -> {
            String id = String.valueOf(e.get(0));
            String trackNumber = String.valueOf(e.get(1)).split("-")[0];

            String message = "{\"eventId\":\"%s\",\"eventType\":30,\"packageNumber\":\"%s\",\"packageType\":0,\"vendorCode\":\"DH\"}";
            String messageValue = String.format(message, id, trackNumber);
            String format = String.format(template, id, messageValue,fileName);
            sqlList.add(format);
        });
        String exportUrl = "C:\\Users\\ASUS\\Desktop\\轨迹信息处理\\";
        ExportUtil.writeDataToFile(sqlList, exportUrl, fileName);
        System.out.println("完成:"+(list.size()-1));
    }
}
